<?php
	if (!isset($_POST['CliNacionalidad'])) {
	$_POST['CliNacionalidad'] = 0;
	}
	function Obj_Create_Client() { 
	$Msg_ALERT = '<img alt="Campo Incorrecto" src="'.$GLOBALS['GFX'].'alert.png">';
	$QCall = "SELECT * FROM main_clients ORDER BY client_number DESC LIMIT 0,1";
	$Call = $GLOBALS['CONN']->db_array($QCall);
	for ($i = 1; $i <= $Call[0]; $i++) { 
	$new_number = $Call[$i]['client_number']+1;
	form_pr('','',$_SERVER['PHP_SELF'],'post');
	?>
	<table>
      <tr bgcolor="#F2F2F2">
        <td width="20%" rowspan="4" valign="top">Cliente
		<div class="Alert">Como consta no documento de identifica��o.</div></td>
        <td width="13%">N&uacute;mero</td>
        <td width="67%"><?php echo $new_number;?><input type="hidden" name="client_number" value="<?php echo $new_number;?>">
		 <?php if(isset($_POST['client_number']) && $_POST['client_number'] == "") { print $Msg_ALERT;}?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td>Classe: </td>
        <td><select name="client_profile_ref">
	<?php 
	$QList = "SELECT * FROM main_settings_clients";
	$List = $GLOBALS['CONN']->db_array($QList);
	for ($l = 1; $l <= $List[0]; $l++) { ?>
	<option value="<?php echo $List[$l]['ref'];?>"><?php echo $List[$l]['profile_name'];?></option>
	<?php } ?>
        </select></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td width="13%" valign="top">Nome Pr�prio: </td>
        <td width="67%"><input value="<?php if (isset($_POST['name'])) {print $_POST['name'];}?>" name="name" type="text" id="name" size="20" maxlength="255">
         <?php if(isset($_POST['name']) && $_POST['name'] == "") { print $Msg_ALERT;}?>
		 <?php // <input name="name_middle" type="text" id="name_middle" size="50" maxlength="255"> ?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td>Apelidos: </td>
        <td width="67%"><input value="<?php if (isset($_POST['name_last'])) {print $_POST['name_last'];}?>" name="name_last" type="text" id="name_last" size="40" maxlength="255"><?php if(isset($_POST['name_last']) && $_POST['name_last'] == "") { print $Msg_ALERT;}?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td width="20%" valign="top">Nacionalidade</td>
        <td></td>
        <td><?php 
		SchemaCONN();
		$Qur = "SELECT pai_CodElite AS ID, pai_NombreESP AS NAME FROM hd_paises";
		mn_field('select','ED','CliNacionalidad',$_POST['CliNacionalidad'],$Qur,'','',''); ?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td width="20%" rowspan="2" valign="top">Morada</td>
        <td>Rua </td>
        <td><input value="<?php if (isset($_POST['Address'])) {print $_POST['Address'];}?>" name="Address" type="text" id="Address" size="50" maxlength="255"><?php if(isset($_POST['Address']) && $_POST['Address'] == "") { print $Msg_ALERT;}?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td>Cidade </td>
        <td><input value="<?php if (isset($_POST['RefCity'])) {print $_POST['RefCity'];}?>" name="RefCity" type="text" id="RefCity" size="30" maxlength="255"><?php if(isset($_POST['RefCity']) && $_POST['RefCity'] == "") { print $Msg_ALERT;}?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td width="20%" valign="top">Contactos</td>
        <td>Telefone </td>
        <td width="67%"><input value="<?php if (isset($_POST['Phone'])) {print $_POST['Phone'];}?>" name="Phone" type="text" id="Phone" size="12" maxlength="40"><?php if(isset($_POST['Phone']) && $_POST['Phone'] == "") { print $Msg_ALERT;}?></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td rowspan="2" valign="top">Documentos:</td>
        <td colspan="2"><table width="400"  border="0" cellpadding="1" cellspacing="0">
          <tr>
            <td>Tipo</td>
            <td>N&uacute;mero</td>
            <td>CÓpia</td>
            <td>&nbsp;</td>
          </tr>
          <tr bgcolor="#CCCCCC">
            <td><select name="id_type" id="id_type">
              <?php 
	$QList = "SELECT * FROM main_settings_clients_doctypes";
	$List = $GLOBALS['CONN']->db_array($QList);
	for ($l = 1; $l <= $List[0]; $l++) { ?>
              <option value="<?php echo $List[$l]['ref'];?>" <?php if(isset($_POST['id_type']) && $List[$l]['ref'] == $_POST['id_type']) {print 'selected';} ?>>
              <?php echo $List[$l]['name'];?>
              </option>
              <?php } ?>
            </select></td>
            <td><input value="<?php if (isset($_POST['id_number'])) {print $_POST['id_number'];}?>" name="id_number" type="text" id="id_number2" maxlength="255">
            <?php if(isset($_POST['id_number']) && $_POST['id_number'] == "") { print $Msg_ALERT;}?></td>
            <td><?php mn_field('file','ED','FILE','','100','20','',''); ?></td>
            <td><?php mn_field('submit','ED','SubDOC','Guardar','','','',''); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td colspan="2">
		<table width="400"  border="0" cellspacing="0" cellpadding="1">
        <?php
		$ListDC = $GLOBALS['CONN']->db_array("SELECT dtd_Numero, main_settings_clients_doctypes.name AS TypeNAME, FILE 
				FROM hd_documentos 
				INNER JOIN main_settings_clients_doctypes ON main_settings_clients_doctypes.ref = hd_documentos.dtd_Tipo
				WHERE dtd_Cliente = {$new_number}");
		for ($r = 1; $r <= $ListDC[0]; $r++) { ?>
		  <tr>
            <td><?php echo $ListDC[$r]['TypeNAME'];?></td>
            <td><?php echo $ListDC[$r]['dtd_Numero'];?>
            </td>
            <td><a href="<?php echo $ListDC[$r]['FILE'];?>">Ver</a></td>
          </tr>
		 <?php } ?>
        </table></td>
      </tr>
      <tr bgcolor="#F2F2F2">
        <td colspan="2">&nbsp; </td>
        <td width="67%"><input name="ClientSave" type="submit" id="Save" value="Salvar"></td>
      </tr>
	  </table>
  </form>
<?php }
} ?>